<template>
  <div>
    <el-container class="pageWrapper">
      <el-aside width="200px">
        <h3>黑马头条</h3>
        <h4>文章管理</h4>
        <el-menu
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
        >
          <el-menu-item
            index="2"
            @click="$router.push('/postlist').catch((err) => {})"
          >
            <i class="el-icon-menu"></i>
            <span slot="title">文章列表</span>
          </el-menu-item>

          <el-menu-item
            index="4"
            @click="$router.push('/editpost').catch((err) => {})"
          >
            <i class="el-icon-setting"></i>
            <span slot="title">发布文章</span>
          </el-menu-item>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <div class="demo-image" v-if="headImg">
            <el-image
              :src="headImg"
              fit="cover"
              style="width:50px;height:50px; border-radius: 50%;"
            ></el-image>
          </div>
          <div v-else-if="!headImg && config">
            <img src="../assets/w1.gif" alt="" />
          </div>
          <span>{{ nickname }}</span>
        </el-header>
        <el-main>
          <!-- 渲染子路由 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      headImg: "",
      nickname: "",
      config: "",
    };
  },
  created() {
    // 根据url的id获取用户信息
    this.$axios({
      url: "/user/" + localStorage.getItem("myuserid"),
    }).then((res) => {
      console.log(res, 11);
      const newRes = res.data.data;
      if (res.data.message == "获取成功") {
        // 将获取的数据里面的config作为请求数据完成的判断
        this.config = res.config;
        // console.log("获取成功");
        this.nickname = newRes.nickname;
        if (newRes.head_img.indexOf("http") == -1 && newRes.head_img) {
          this.headImg = this.$axios.defaults.baseURL + newRes.head_img;
          // console.log(this.headImg, 11);
        }
      }
    });
  },
};
</script>

<style lang="less" scoped>
.pageWrapper {
  height: 100vh;
}
.el-header {
  padding-right: 300px;
  background-color: #333;
  color: #333;
  text-align: center;
  line-height: 16px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  .el-image {
    margin-right: 16px;
  }
  img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 10px;
  }
  span {
    color: #fff;
  }
}

.el-aside {
  background-color: #000;
  color: #fff;
  text-align: center;
  line-height: 200px;

  h3 {
    height: 60px;
    line-height: 60px;
    color: #fff;
  }
  h4 {
    margin-top: 20px;
    padding-right: 40px;
    height: 30px;
    line-height: 30px;
    color: #fff;
  }
  .el-menu {
    border: none;
    background-color: #000;

    .el-menu-item {
      color: #fff;
      // &:hover {
      //   color: #000;
      // }
    }
  }
}

.el-main {
  background-color: #f2f2f2;
  color: #333;
  // text-align: center;
  /deep/ .ql-toolbar {
    line-height: 1;
  }
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
